<!DOCTYPE html>
<html>
  <head>
    <title>Listing 7.5</title>
    <script type="text/javascript" src="../scripts/assert.js"></script>
    <link href="../styles/assert.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <script type="text/javascript">

      var html = "<div class='test'><b>Hello</b> <i>world!</i></div>";

      var results = html.match(/<(\/?)(\w+)([^>]*?)>/);          //#1

      assert(results[0] == "<div class='test'>", "The entire match.");
      assert(results[1] == "", "The (missing) slash.");
      assert(results[2] == "div", "The tag name.");
      assert(results[3] == " class='test'", "The attributes.");

      var all = html.match(/<(\/?)(\w+)([^>]*?)>/g);              //#2

      assert(all[0] == "<div class='test'>", "Opening div tag.");
      assert(all[1] == "<b>", "Opening b tag.");
      assert(all[2] == "</b>", "Closing b tag.");
      assert(all[3] == "<i>", "Opening i tag.");
      assert(all[4] == "</i>", "Closing i tag.");
      assert(all[5] == "</div>", "Closing div tag.");

    </script>

  </body>
</html>
